package com.egao.common.manage.school;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.student.constants.StudentConstants;
import com.egao.common.module.student.entity.Student;
import com.egao.common.module.student.entity.StudentBasic;
import com.egao.common.module.student.service.StudentBasicService;
import com.egao.common.module.student.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 校基层就业管理
 * @author lsh
 */
@Api(tags = "校基层就业管理")
@RestController
@RequestMapping("${api}")
public class SchoolBasicController extends BaseController {

    @Autowired
    private StudentBasicService basicService;

    @Autowired
    private StudentService studentService;

    @PreAuthorize("hasAuthority('school')")
    @ApiOperation(value = "校基层就业管理列表")
    @ApiPageParam
    @GetMapping("/school/basic/list")
    public PageResult<StudentBasic> basicPage(HttpServletRequest request) {
        PageParam<StudentBasic> pageParam = new PageParam<>(request);
        return new PageResult<>(basicService.listPage(pageParam), pageParam.getTotal());
    }

    @PreAuthorize("hasAuthority('school')")
    @ApiOperation(value = "校基层就业填报详情")
    @ApiPageParam
    @GetMapping("/school/basic/detail")
    public JsonResult basicdetail(Integer id) {
        if (id == null) {
            return JsonResult.error("传入参数异常");
        }
        return JsonResult.ok().setData(basicService.BasicDetailSchool(id));
    }

    @PreAuthorize("hasAuthority('school')")
    @ApiOperation(value = "校基层就业填报审批")
    @ApiPageParam
    @PutMapping("/school/basic/submit")
    public JsonResult basicSave(@RequestBody StudentBasic studentBasic) {
        if (studentBasic == null) {
            return JsonResult.error("传入参数异常");
        }
        boolean save = basicService.updateById(studentBasic);
        if (save){
            return JsonResult.ok();
        }
        return JsonResult.error("服务器异常，请联系管理人员！");
    }

}
